package com.qf.osmproduct.product.controller;

import com.qf.common.core.common.R;
import com.qf.common.core.entity.product.Product;
import com.qf.osmproduct.product.param.ProductParam;
import com.qf.osmproduct.product.param.UserFavoriteParam;
import com.qf.osmproduct.product.service.ProductService;
import com.qf.osmproduct.product.service.UserFavoriteService;
import com.qf.osmproduct.product.vo.GoodsVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 天--道--酬--勤
 *
 * @author LiangGaoQiang
 * @ClassName ProductController
 * @Date: 2025/6/10 17:18
 * @Description: 描述
 */
@RestController
@RequestMapping("/Goods")
public class ProductController {

    @Resource
    private ProductService productService;

    @Resource
    private UserFavoriteService userFavoriteService;


    /**
     * 获取搜索热词
     *
     * @return 热点商品名称，前10个
     */
    @GetMapping("/getSearchHot")
    public R getHotProductName() {
        // 获得热搜商品
        List<String> list = productService.getHotProductName();
        return R.ok(list);
    }


    /**
     * 搜索商品
     *
     * @param productParam 商品名称，模糊查询
     * @return 商品列表
     */
    @GetMapping("/getGoods")
    public R searchProduct(ProductParam productParam) {
        List<Product> list = productService.searchProduct(productParam);
        return R.ok(list);
    }

    @GetMapping("/GetGoodsInfo")
    public R getGoodsInfo(Integer goodsId) {
        GoodsVO goodsVO = productService.getProductById(goodsId);
        return R.ok(goodsVO);
    }


    /**
     * 添加收藏
     *
     * @param favoriteParam 收藏参数
     * @return 成功或失败
     */
    @PostMapping("/createFavorite")
    public R addFavorite(@RequestBody UserFavoriteParam favoriteParam) {
        boolean result = userFavoriteService.addFavorite(favoriteParam);
        if (result) {
            return R.ok("收藏成功");
        }
        return R.fail("收藏失败");
    }


    @GetMapping("/removeFavorite")
    public R removeFavorite(UserFavoriteParam favoriteParam) {
        boolean result = userFavoriteService.removeFavorite(favoriteParam);
        if (result) {
            return R.ok("取消收藏成功");
        }
        return R.fail("取消收藏失败");
    }


    /**
     * 获取商品信息
     *
     * @param productIds 商品ID列表
     * @return 商品列表信息
     */
    @GetMapping("/getProductInfo")
    public List<Product> getProductInfo(@RequestParam("productIds") List<Integer> productIds){
        List<Product> productList = productService.getProductInfo(productIds);
        return productList;
    }
}
